local skel = fk.CreateSkill {
  name = "emo__shencha",
  tags = {Skill.Permanent},
}

skel:addEffect(fk.GameStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return (player.general == "moe__yangjian" or player.deputyGeneral == "moe__yangjian")
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player, room:getOtherPlayers(player, false))
    room:delay(1500)
    local cards = {}
    for _, p in ipairs(room:getOtherPlayers(player, false)) do
      table.insertTable(cards, p:getCardIds("h"))
    end
    local num = math.min(#room.players, #cards)
    if num == 0 then return end
    table.shuffle(cards)
    cards = room:askToChooseCards(player, {
      max = num, min = num, target = player, flag = { card_data = { { skel.name, cards } } },
      skill_name = skel.name, prompt = "#emo__shencha-card:::"..num
    })
    room:setPlayerMark(player, "emo__shencha_record", cards)
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return target ~= player and table.find(Card:getIdList(data.card), function (id)
      return table.contains(player:getTableMark("emo__shencha_record"), id)
    end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:doIndicate(player, {target})
    local all_choices = {
      "#emo__shencha_invalCard:::"..data.card:toLogString(),
      "#emo__shencha_invalSkill:"..target.id,
      "#emo__shencha_showRole:"..target.id,
      "#emo__shencha_useSlash",
    }
    local choices = {all_choices[1]}
    local skillMark = target:getTableMark("@[:]emo__shencha_inval-round")
    local skills = table.filter(table.map(target:getAllSkills(), Util.NameMapper), function(s)
      return not table.contains(skillMark, s)
    end)
    if #skills > 0 then
      table.insert(choices, all_choices[2])
    end
    if not target.role_shown then
      table.insert(choices, all_choices[3])
    end
    local slash = Fk:cloneCard("thunder__slash")
    slash.skillName = skel.name
    if not player:prohibitUse(slash) then
      table.insert(choices, all_choices[4])
    end
    choices = room:askToChoices(player, {
      choices = choices, min_num = 1, max_num = 2, cancelable = true, skill_name = skel.name,
      all_choices = all_choices
    })
    if table.contains(choices, all_choices[2]) then
      local ch = room:askToChoice(player, {
        choices = skills, skill_name = skel.name, detailed = true, prompt = "#emo__shencha-skill:"..target.id
      })
      room:addTableMark(target, "@[:]emo__shencha_inval-round", ch)
    end
    if table.contains(choices, all_choices[3]) then
      room:setPlayerProperty(target, "role_shown", true)
    end
    if table.contains(choices, all_choices[1]) then
      data:removeAllTargets()
      data.toCard = nil
      local subcards = room:getSubcardsByRule(data.card, {Card.Processing})
      if #subcards > 0 then
        room:obtainCard(player, subcards, true, fk.ReasonJustMove, player, skel.name)
      end
    end
    if table.contains(choices, all_choices[4]) then
      room:askToUseVirtualCard(player, {
        name = "thunder__slash", skill_name = skel.name, extra_data = {bypass_distances = true, bypass_times = true}
      })
    end
  end,
})

skel:addEffect("invalidity", {
  invalidity_func = function (self, player, skill)
    return table.contains(player:getTableMark("@[:]emo__shencha_inval-round"), skill.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__shencha"] = "神察",
  [":emo__shencha"] = "持恒技，共鸣技，游戏开始时，你观看所有其他角色的手牌并标记X张（X为本局人数），这些牌被其他角色使用时，你选择至多两项：1.令此牌无效并获得之；2.令其一个技能本轮无效；3.亮出其身份牌；4.视为使用一张雷【杀】。"..
  "<br><font color='grey'><b>*共鸣技：</b>此技能仅在你的武将牌上拥有它时生效。</font>",

  ["@[:]emo__shencha_inval-round"] = "神察:封技",
  ["#emo__shencha-card"] = "神察：请标记 %arg 张牌，其他角色使用时你可令之无效",
  ["#emo__shencha_invalCard"] = "令 %arg 无效并获得",
  ["#emo__shencha_invalSkill"] = "令 %src 一个技能本轮无效",
  ["#emo__shencha_useSlash"] = "视为使用一张雷【杀】",
  ["#emo__shencha_showRole"] = "令 %src 亮出身份牌",
  ["#emo__shencha-skill"] = "神察：选择 %src 一个技能，令之失效直到本轮结束",

  ["$emo__shencha1"] = "是真难灭，是假易除！",
  ["$emo__shencha2"] = "多用神通，藏私无用！",
}


return skel
